--SELECT document_type, version, manufacturer
--
--FROM sys.fulltext_document_types


USE CC_CX --replace with correct DB name

GO

IF OBJECT_ID (N'StormyWeather', N'U') IS NOT NULL

DROP TABLE StormyWeather

GO

CREATE TABLE StormyWeather (

  StormID INT NOT NULL IDENTITY,

  StormHead NVARCHAR(50) NOT NULL,

  StormBody NVARCHAR(MAX) NOT NULL,

  CONSTRAINT [PK_StormyWeather_StormID] PRIMARY KEY CLUSTERED (StormID ASC)

)

GO

-- Populate the StormyWeather table with data

-- that supports various full-text query types.

INSERT INTO StormyWeather (StormHead, StormBody)

VALUES('Stormy Weather Delays Travel',

  'The stormy weather made travel by motor vehicle difficult.')

INSERT INTO StormyWeather (StormHead, StormBody)

VALUES('Stormier Weather on Monday',

  'The stormier weather on Monday made vehicle travel difficult.')

INSERT INTO StormyWeather (StormHead, StormBody)

VALUES('Stormiest Weather in December',

  'December can be the stormiest month, making automobile travel difficult.')

INSERT INTO StormyWeather (StormHead, StormBody)

VALUES('Storm Grows Strong',

  'The storm is growing strong.')

INSERT INTO StormyWeather (StormHead, StormBody)

VALUES('Storms Crossing the Pacific',

  'The storms are lining up across the Pacific Ocean.')

INSERT INTO StormyWeather (StormHead, StormBody)

VALUES('Storm''s Wind Delays Travel',

  'The storm''s wind made car travel difficult on Tuesday.')

INSERT INTO StormyWeather (StormHead, StormBody)

VALUES('Storms'' Flooding Delays Travel',

  'The storms'' flooding made auto travel difficult throughout December.')

INSERT INTO StormyWeather (StormHead, StormBody)

VALUES('Children Run from Room',

  'The children often storm out of the room when upset.')

INSERT INTO StormyWeather (StormHead, StormBody)

VALUES('Boy Runs from Room',

  'The boy storms out of the room when his sister changes the channel.')

INSERT INTO StormyWeather (StormHead, StormBody)

VALUES('Girl Ran from Room',

  'The girl stormed out of the room when her brother ate the cookie.')

INSERT INTO StormyWeather (StormHead, StormBody)

VALUES('Children Running from Room',

  'The children were storming out of the room when the lights went out.')

GO

-- Create a full-text catalog and set it as the default.

CREATE FULLTEXT CATALOG ftcContentDetail

AS DEFAULT

GO

CREATE FULLTEXT CATALOG ftcContentList

AS DEFAULT

GO

-- Create a full-text index on the StormyWeather table.

-- Add the index to the ftcStormyWeather catalog.

CREATE FULLTEXT INDEX ON tblContentDetail(ContentDetail)

KEY INDEX PK_tblContentDetail_ID

ON ftcContentDetail

GO


ALTER FULLTEXT INDEX ON tblContentList

ADD (KeyWord)

KEY INDEX PK_tblContentList_ID

ON ftcContentList

GO

SELECT * FROM tblContentDetail Where CONTAINS(ContentDetail, 'FORMSOF(INFLECTIONAL,fly)')

WHERE CONTAINS(StormHead, 'storm')

SELECT StormID, StormHead,  StormBody FROM StormyWeather

WHERE CONTAINS((StormHead, StormBody), 'storm')

SELECT StormID, StormHead,  StormBody FROM StormyWeather

WHERE CONTAINS(*, 'storm')

SELECT StormID, StormHead,  StormBody FROM StormyWeather

WHERE CONTAINS(StormHead, '"storm" OR "storms" OR "stormy" OR "stormier" OR "stormiest"')

SELECT StormID, StormHead,  StormBody FROM StormyWeather

WHERE CONTAINS(StormHead, '"storm*"') 

SELECT StormID, StormHead,  StormBody FROM StormyWeather

WHERE CONTAINS(StormHead, 'FORMSOF(INFLECTIONAL, run)')

SELECT StormID, StormHead,  StormBody FROM StormyWeather

WHERE CONTAINS(StormBody, 'FORMSOF(THESAURUS, car)')



select cl.ListID, cl.Title, REPLACE(Description,'SIN','<b style="color:yellow">SIN</b>') AS Description, Category, 

CASE cl.CategoryTitle WHEN 'Redemption' THEN 'Redemption' WHEN 'Commercial' THEN 'Commercial' WHEN 'Both' THEN 'Redemption & Commercial' WHEN 'None' THEN '' END CategoryTitle, 

cl.PublishDate, cl.EffectiveDate,
 cl.ExpireDate, cl.Category from tblContentList AS cl INNER JOIN tblContentDetail AS cd ON cl.ListID = cd.ListID 
where (CONTAINS(keyword, 'sin*') or  CONTAINS(Title, 'sin*')  or  CONTAINS(Description, 'sin*') 
OR (CONTAINS(ContentDetail, 'sin*'))) and cl.ContentType IN ('KB', 'NEWS', 'PROMO', 'UPDATES') 
and CONVERT(varchar(8), cl.ExpireDate, 112) > '20100310' and cl.IsOld = 0  GROUP BY cl.PublishDate, cl.ListID, cl.Title, 
cl.Description, cl.CategoryTitle, cl.EffectiveDate, cl.ExpireDate, cl.Category order by cl.PublishDate desc

Select * from tblContentList Where CONTAINS(keyword, 'sin*') or  CONTAINS(Title, 'sin*')  or  CONTAINS(Description, 'sin*')


SELECT cl.ListID, cl.PublishDate, cl.ContentType, REPLACE(REPLACE(Title,'card','<b style="background-color:yellow">card</b>'),
'promotion','<b style="background-color:yellow">promotion</b>') AS Title, cl.Title As ToolTipTitle, cl.Category, 
CASE cl.CategoryTitle WHEN 'Redemption' THEN 'Redemption' WHEN 'Commercial' THEN 'Commercial' WHEN 'Both' 
THEN 'Redemption & Commercial' WHEN 'None' THEN '' END CategoryTitle, cl.LastUpdateDate, cl.EffectiveDate, 
cl.ArchiveDate, cl.ExpireDate, 'New' as Source, 'New Title' as SourceTitle, 'New Date' as SourceDate 
from tblContentList AS cl WHERE  (CONTAINS(Title, 'card OR promotion')) AND  cl.ContentType IN ('KB', 'NEWS', 'PROMO', 'UPDATES') 
AND  CONVERT(varchar(8), cl.ExpireDate, 112) > '20100324' AND  convert(varchar(8), cast(cl.ArchiveDate as DateTime), 112) > '20100324' 
AND  cl.IsOld = 0  GROUP BY   cl.LastUpdateDate, cl.PublishDate, cl.EffectiveDate, cl.ArchiveDate, cl.ExpireDate, cl.Title, cl.Category, 
cl.CategoryTitle, cl.ContentType, cl.ListID  ORDER BY cl.PublishDate, cl.ArchiveDate  DESC 

select * from tblContentList cl wHERE 

CONVERT(varchar(8), cl.ExpireDate, 112) < '20100324'

Baggage Information : LIMITATION OF LIQUIDS IN HAND LUGGAGE AT EUROPEAN AIRPORTS


SELECT cl.ListID, cl.PublishDate, cl.ContentType, Title AS Title, cl.Title As ToolTipTitle, 
CASE cl.CategoryTitle WHEN 'Redemption' THEN 'Redemption' WHEN 'Commercial' THEN 'Commercial' 
WHEN 'Both' THEN 'Redemption & Commercial' WHEN 'None' THEN '' END CategoryTitle, 
cl.LastUpdateDate, cl.EffectiveDate, cl.ArchiveDate, cl.ExpireDate, 'New' as Source, 
'New Title' as SourceTitle, 'New Date' as SourceDate from tblContentList AS cl 
GROUP BY cl.ListID, cl.PublishDate, cl.ArchiveDate, cl.ContentType, cl.Title, cl.CategoryTitle, 
cl.LastUpdateDate, cl.EffectiveDate, cl.ExpireDate, cl.IsOld  HAVING 
 cl.ContentType IN ('KB', 'NEWS', 'PROMO', 'UPDATES') AND  CONVERT(varchar(8), cl.ExpireDate, 112) > '20100324' 
AND  convert(varchar(8), cast(cl.ArchiveDate as DateTime), 112) > '20100324' AND  cl.IsOld = 0  
Order By cl.ArchiveDate, cl.PublishDate DESC

ORDER BY cl.PublishDate, cl.ArchiveDate DESC 

SELECT cl.ListID, cl.PublishDate, cl.ContentType, Title AS Title, cl.Title As ToolTipTitle, 
CASE cl.CategoryTitle WHEN 'Redemption' THEN 'Redemption' WHEN 'Commercial' THEN 'Commercial' 
WHEN 'Both' THEN 'Redemption & Commercial' WHEN 'None' THEN '' END CategoryTitle, cl.LastUpdateDate, 
cl.EffectiveDate, ArchiveDate = CASE Convert(char(4),cl.ArchiveDate, 112) WHEN '2099' THEN '' ELSE Convert(char(12),cl.ArchiveDate,103) END, cl.ExpireDate, 'New' as Source, 'New Title' as SourceTitle, 
'New Date' as SourceDate from tblContentList AS cl 
 GROUP BY cl.ListID, cl.PublishDate, cl.ArchiveDate, 
cl.ContentType, cl.Title, 
cl.CategoryTitle, cl.LastUpdateDate, cl.EffectiveDate, cl.ExpireDate, cl.IsOld  
HAVING  cl.ContentType IN ('KB', 'NEWS', 'PROMO', 'UPDATES') 
AND  CONVERT(varchar(8), cl.ExpireDate, 112) > '20100324' 
AND  convert(varchar(8), cast(cl.ArchiveDate as DateTime), 112) > '20100324' 
AND  cl.IsOld = 0  ORDER BY cl.ArchiveDate, cl.PublishDate DESC 

                 